exports.close_beta_test_user = (tradeId) ->
    return true unless process.env.CLOSE_BETA_TEST_USER
    cbt_users = process.env.CLOSE_BETA_TEST_USER.split /[:,\s]+/
    return true if tradeId in cbt_users
    return false

exports.parse_YYYYMMDD = (s) ->
    #YYYYMMDD格式的日期转成Date对象
    s = s?.toString()
    # return null unless s?.match(/(19|20)\d\d(0[1-9]|1[0-2])(0[1-9]|[1-2]\d|3[01])/)
    unless /\d{8,8}/.test(s)
      return null
    #d = new Date(- 8*3600*1000)
    d = new Date(0)
    d.setYear(parseInt(s[0..3]))
    d.setMonth(parseInt(s[4..5]) - 1)
    d.setDate(parseInt(s[6..7]))
    return d

exports.split_fields = require("../lib/utils").split_fields        

log_error = require("./logging").error_logger.error

# 返回只记录处理错误信息的callback
exports.make_log_err_cb = (err_msg) ->
  (err) ->
    if err
      log_error err_msg + ":" + JSON.stringify(err)

# 把n转化为数字返回，如果失败就返回缺省值  
exports.convert_to_number = (n,dft) ->
  if isNaN(Number(n))
    return dft
  else
    return Number(n)
    
